
var config = require('../../../config/systemConfig.json');

function CheckSignManager () {

    var uidToSign = {}; // 玩家uid 对应验证码以及玩家的手机信息
}

CheckSignManager.prototype = {

    init : function (callback) {
        this.uidToSign = {};

        callback();
    },

    /**
     * 获取验证码
     * @param uid
     * @returns {*|{}}
     */
    getCheckData : function (uid) {

        return this.uidToSign[uid];
    },

    /**
     * 添加玩家验证码数据
     * @param uid
     * @param phone
     * @param subConfig
     * @return {}
     */
    addCheckSign : function (uid, phone, subConfig) {

        if (!uid) {
            return;
        }

        var data = {};

        // 记录一下当前的时间戳
        data.time = Date.getStamp();

        // 生成验证码
        data.sign = Ext.generateRandomStr (subConfig.signLength, 0);

        data.phone = phone;

        this.uidToSign[uid] = data;

        return data;
    },

    getConfig : function (id, attr) {

        var content = config[id];

        if (!attr) {
            return content;
        }

        return content[attr];
    }
};

exports.CheckSignManager = CheckSignManager;